package day0409;

/**
 * @Author Stringzhua
 * @Date 2024/4/9 16:42
 * description:有一家咖啡店提供HouseBlend咖啡和Espresso咖啡。
 * 每一种咖啡需要用到如下配料：牛奶，摩卡。
 * 请使用装饰模式构建咖啡店程序计算每种饮料的花费以及其描述。
 */
interface Coffee {
    double cost();
    String description();
}

class HouseBlend implements Coffee {
    @Override
    public double cost() {
        return 1.0;
    }

    @Override
    public String description() {
        return "HouseBlend咖啡";
    }
}

class Espresso implements Coffee {
    @Override
    public double cost() {
        return 2.0;
    }

    @Override
    public String description() {
        return "Espresso咖啡";
    }
}

abstract class CoffeeDecorator implements Coffee {
    protected Coffee coffee;

    public CoffeeDecorator(Coffee coffee) {
        this.coffee = coffee;
    }

    @Override
    public double cost() {
        return coffee.cost();
    }

    @Override
    public String description() {
        return coffee.description();
    }
}

class MilkDecorator extends CoffeeDecorator {
    public MilkDecorator(Coffee coffee) {
        super(coffee);
    }

    @Override
    public double cost() {
        return coffee.cost() + 0.5;
    }

    @Override
    public String description() {
        return coffee.description() + ", 牛奶";
    }
}

class MochaDecorator extends CoffeeDecorator {
    public MochaDecorator(Coffee coffee) {
        super(coffee);
    }

    @Override
    public double cost() {
        return coffee.cost() + 0.7;
    }

    @Override
    public String description() {
        return coffee.description() + ", 摩卡";
    }
}

public class CoffeeShop {
    public static void main(String[] args) {
        Coffee houseBlend = new HouseBlend();
        Coffee espresso = new Espresso();

        Coffee milkHouseBlend = new MilkDecorator(houseBlend);
        Coffee mochaEspresso = new MochaDecorator(espresso);

        System.out.println(milkHouseBlend.description() + ": " + milkHouseBlend.cost());
        System.out.println(mochaEspresso.description() + ": " + mochaEspresso.cost());
    }
}
